package dao;

import aop.Log;
import aop.LogSaver;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Repository
public class LogSaverImpl {
    public void logsaver(Log log) throws SQLException {
        Date da = new Date(System.currentTimeMillis());
        //获取链接
        Connection conn = LogSaver.getConnection();
        //sql
        String sql = "INSERT INTO dc_log(username,date) VALUE(?,?)";
        //预编译
        PreparedStatement ptmt = conn.prepareStatement(sql); //预编译SQL，减少sql执行

        ptmt.setString(1, log.getUserName());
        ptmt.setDate(2,da);


        //执行
        ptmt.execute();
    }

/*    public static void main(String[] args) throws SQLException {
        Date date = new Date(System.currentTimeMillis());
        //获取链接
        Connection conn = LogSaver.getConnection();
        //sql
        String sql = "INSERT INTO dc_log(username,DATE) VALUE(?,?)";
        //预编译
        PreparedStatement ptmt = conn.prepareStatement(sql); //预编译SQL，减少sql执行

        System.out.println(date);
        ptmt.setString(1,);
        ptmt.setDate(2,date);

        ptmt.execute();
    }*/
}
